package com.ftg.learn.amqp.workqueue;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeoutException;

/**
 * @author 布衣
 */
public class BaseConnection {

    private static Properties properties = new Properties();

    static{
        try {
            properties.load(BaseConnection.class.getClassLoader().getResourceAsStream("rabbitdb.properties"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Connection getRabbitConnection() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(properties.getProperty("rabbitdb.host"));
        factory.setPort(Integer.valueOf(properties.getProperty("rabbitdb.port")));
        factory.setUsername(properties.getProperty("rabbitdb.username"));
        factory.setPassword(properties.getProperty("rabbitdb.password"));
        factory.setVirtualHost(properties.getProperty("rabbitdb.virtualhost"));
        return factory.newConnection();
    }

    //

}
